﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WFTest.Entity;

namespace WFTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] vs = new string[] { "name","no", "age", "ww", "qq"};
            studet studet1 = new studet()
            {
                name = "q",
                no = "1",
                age = 4354,
                ww = "似懂非懂",
                qq = "古典风格",
            };
            studet studet2 = new studet()
            {
                name = "w",
                no = "2",
                age = 8,
                ww = "fsdfvdsg",
                qq = "古典风格",
            };
            studet studet3 = new studet()
            {
                name = "e",
                no = "3",
                age = 10,
                ww = "的说法是股东股份",
                qq = "十分微弱",
            };
            studet studet4 = new studet()
            {
                name = "q",
                no = "4",
                age = 10,
                ww = "撒旦发射点",
                qq = "古典风格",
            };
            studet studet5 = new studet()
            {
                name = "w",
                no = "2",
                age = 8,
                ww = "fsdfvdsg",
                qq = "古典风格",
            };
            studet studet6 = new studet()
            {
                name = "e",
                no = "6",
                age = 11,
                ww = "撒旦发射点",
                qq = "古典风格",
            };
            List<studet> list1 = new List<studet>();
            list1.Add(studet1);
            list1.Add(studet2);
            list1.Add(studet3);

            List<studet> list2 = new List<studet>();
            list2.Add(studet4);
            list2.Add(studet5);
            list2.Add(studet6);
            var li1 = list1.Intersect(list2, new Comparer<studet>(vs)).ToList();
            var li2 = list2.Intersect(list1, new Comparer<studet>(vs)).ToList();

            

        }
    }

    public class Comparer<T> : IEqualityComparer<T>
    {
        string[] _vs;
        public Comparer(string[] vs)
        {
            _vs = vs;
        }
        public bool Equals(T x1, T x2)
        {
           bool flag=false;
            if (ReferenceEquals(x1, x2))
                return true;
            //if (x1 is null || x2 is null)
            //    return false;
            foreach (var v in _vs)
            {

                var v1 = x1.GetType().GetProperty(v).GetValue(x1).ToString();
                var v2 = x2.GetType().GetProperty(v).GetValue(x2).ToString();
                if (v1!= v2)
                {
                    flag=true;
                    break;
                }

            }
            return flag;
        }

        public int GetHashCode(T p) => p.GetType().GetProperty("name").GetValue(p).ToString().GetHashCode();
    }



    public class studet
    {
        public string name { get; set; }
        public string no { get; set; }
        public int age { get; set; }
        public string ww { get; set; }
        public string qq { get; set; }
    }




}
